package com.rockxin.cat.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.rockxin.cat.R;
import com.rockxin.cat.base.BaseActivity;
import com.rockxin.cat.network.CatNetWork;
import com.rockxin.cat.network.HttpResult;
import com.rockxin.cat.utils.RegexUtils;
import com.rockxin.cat.utils.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;
import rx.Subscriber;

/**
 * 实名认证
 */
public class RealNameActivity extends BaseActivity {

    @BindView(R.id.back_img)
    ImageView backImg;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.realName)
    EditText realName;
    @BindView(R.id.realNum)
    EditText realNum;
    @BindView(R.id.addBankCard)
    TextView addBankCard;

    private String token;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int setLayout() {
        return R.layout.activity_real_name;
    }

    @Override
    public void initData() {
        title.setText("实名认证");
        realNum.setSingleLine();

        Intent getIntent = getIntent();
        String type = getIntent.getStringExtra("type");
        token = getIntent.getStringExtra("token");
    }

    @OnClick({R.id.back_img, R.id.addBankCard})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_img:
                finish();
                break;
            case R.id.addBankCard:
                if (TextUtils.isEmpty(realName.getText().toString())) {
                    ToastUtils.showLongToastSafe("请输入真实姓名");
                    return;
                }
                if (TextUtils.isEmpty(realNum.getText().toString())) {
                    ToastUtils.showLongToastSafe("请输入身份证号码");
                    return;
                }
                if (!RegexUtils.isIDCard18(realNum.getText().toString())) {
                    ToastUtils.showLongToastSafe("请输入正确的身份证号码");
                    return;
                }
                CatNetWork catNetWork = new CatNetWork();
                catNetWork.renzheng(token, realName.getText().toString(), realNum.getText().toString(), new Subscriber<HttpResult>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(HttpResult httpResult) {
                        if (httpResult.getStatus() == 1) {
                            Intent intent = new Intent(RealNameActivity.this, AddBankCardActivity.class);
                            intent.putExtra("token", token);
                            startActivity(intent);
                            finish();
                        }
                    }
                });
                break;

        }
    }
}
